﻿@{
    ViewBag.Title = "UserInfoAddView";
}
@using (Ajax.BeginForm("SaveUserInfo", new AjaxOptions { OnBegin = "CheckSubmit", OnSuccess = "SaveResult", OnComplete = "complete", OnFailure = "SaveResult" }))
{
    <!-- Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">添加</h4>
                </div>
                <div class="modal-body">
                    <form>
                        <div class="form-group">
                            <label for="brand_name" class="control-label">会员ID</label>
                            <input type="text" class="form-control" id="UserId" readonly="readonly" name="UserId" value="@ViewData["MaxUserId"]">
                        </div>
                        <div class="form-group">
                            <label for="brand_name" class="control-label">会员姓名:<span style="color: gray; font-size: 11px; margin-left: 20px;">（请填写中文）</span></label>
                            <span data-toggle="popover" data-placement="top" data-trigger="focus" data-content="填写会员姓名！">
                                <input type="text" onkeyup="value = value.replace(/[^\u4E00-\u9FA5]/g, '')" min="3" maxlength="27" class="form-control" id="UserName" name="UserName">
                            </span>
                        </div>
                        <div class="form-group">
                            <label for="brand_name" class="control-label">年龄:<span style="color: gray; font-size: 11px; margin-left: 20px;">（年龄范围：18至99岁）</span></label>
                            <span data-toggle="popover" data-placement="top" data-trigger="focus" data-content="填写会员年龄！">
                                <input type="number" class="form-control" id="UserAge" name="UserAge">
                            </span>
                        </div>
                        <div class="form-group">
                            <label for="brand_name" class="control-label">手机号:</label>
                            <span data-toggle="popover" data-placement="top" data-trigger="focus" data-content="填写会员手机号！">
                                <input type="number" class="form-control" id="UserTell" name="UserTell">
                            </span>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary">保存</button>
                </div>
            </div>
        </div>
    </div>

}

<script type="text/javascript">
    function CheckSubmit() {
        if ($.trim($("#UserName").val()).length == 0) {
            alert("填写会员姓名!");
            return false;
        }
        if ($.trim($("#UserAge").val()).length == 0) {
            alert("填写会员年龄!");
            return false;
        }
        if ($("#UserAge").val() < 18 || $("#UserAge").val() > 99) {
            alert("填写正确的会员年龄!");
            return false;
        }
        if ($.trim($("#UserTell").val()).length == 0) {
            alert("填写会员手机号!");
            return false;
        }
        return true;
    }

    function SaveResult(data) {
        if (data.IsSuccess) {
            alert("恭喜：保存成功！");
            $("#myModal").modal('hide');
            $("#btnSearch").click();

        } else {
            alert("抱歉，保存失败:" + data.Message);
        }

    }

</script>